package com.mercury.ec.module.air.dal.mysql.order;

import com.mercury.ec.framework.common.pojo.PageResult;
import com.mercury.ec.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.mercury.ec.framework.mybatis.core.mapper.BaseMapperX;
import com.mercury.ec.module.air.controller.admin.order.vo.orderroute.AirOrderRoutePageReqVO;
import com.mercury.ec.module.air.controller.admin.order.vo.orderroute.AirOrderRouteRespVO;
import com.mercury.ec.module.air.dal.dataobject.order.AirOrderRouteDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 机票订单行程 Mapper
 *
 * @author hesx
 */
@Mapper
public interface AirOrderRouteMapper extends BaseMapperX<AirOrderRouteDO> {

    default PageResult<AirOrderRouteDO> selectPage(AirOrderRoutePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AirOrderRouteDO>()
                .eqIfPresent(AirOrderRouteDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(AirOrderRouteDO::getSerialNo, reqVO.getSerialNo())
                .eqIfPresent(AirOrderRouteDO::getOriginOrderRouteId, reqVO.getOriginOrderRouteId())
                .likeIfPresent(AirOrderRouteDO::getAirlineNo, reqVO.getAirlineNo())
                .likeIfPresent(AirOrderRouteDO::getCarrierAirlineNo, reqVO.getCarrierAirlineNo())
                .likeIfPresent(AirOrderRouteDO::getFlightNo, reqVO.getFlightNo())
                .likeIfPresent(AirOrderRouteDO::getCabin, reqVO.getCabin())
                .likeIfPresent(AirOrderRouteDO::getDepart, reqVO.getDepart())
                .likeIfPresent(AirOrderRouteDO::getArrive, reqVO.getArrive())
                .betweenIfPresent(AirOrderRouteDO::getFlightDate, reqVO.getFlightDate())
                .betweenIfPresent(AirOrderRouteDO::getArriveDate, reqVO.getArriveDate())
                .eqIfPresent(AirOrderRouteDO::getDepartTime, reqVO.getDepartTime())
                .eqIfPresent(AirOrderRouteDO::getArriveTime, reqVO.getArriveTime())
                .likeIfPresent(AirOrderRouteDO::getDepartTerminal, reqVO.getDepartTerminal())
                .likeIfPresent(AirOrderRouteDO::getArriveTerminal, reqVO.getArriveTerminal())
                .likeIfPresent(AirOrderRouteDO::getAirModel, reqVO.getAirModel())
                .likeIfPresent(AirOrderRouteDO::getAirModelName, reqVO.getAirModelName())
                .eqIfPresent(AirOrderRouteDO::getHaveFood, reqVO.getHaveFood())
                .eqIfPresent(AirOrderRouteDO::getStop, reqVO.getStop())
                .likeIfPresent(AirOrderRouteDO::getStopAirportNo, reqVO.getStopAirportNo())
                .likeIfPresent(AirOrderRouteDO::getStopTerminal, reqVO.getStopTerminal())
                .eqIfPresent(AirOrderRouteDO::getShare, reqVO.getShare())
                .eqIfPresent(AirOrderRouteDO::getThrough, reqVO.getThrough())
                .eqIfPresent(AirOrderRouteDO::getPunctualityRate, reqVO.getPunctualityRate())
                .betweenIfPresent(AirOrderRouteDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(AirOrderRouteDO::getBaggageWeight, reqVO.getBaggageWeight())
                .eqIfPresent(AirOrderRouteDO::getFoodType, reqVO.getFoodType())
                .orderByDesc(AirOrderRouteDO::getId));
    }

    List<AirOrderRouteRespVO> selectByOrderId(Long orderId);

    default void deleteByOrderId(Long orderId) {
        delete(AirOrderRouteDO::getOrderId, orderId);
    }
}
